package rocketman;
/*
Copyright (C) <year> <name of author>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.ImageIcon;
import java.awt.Toolkit;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import java.util.*;

class Player
{
int key;
static LinkedList<Bullet> friendlybullets;
protected int playerx, playery, playerw, playerh, dx, dy;
protected StateImageLibrary images = new StateImageLibrary();
String prefix = "./pics/";
Image playerimg;
protected int jumpcounter = 0;
public Player(int startx, int starty)
{
	playerx = startx;
	playery = starty;
	playerw = 64;
	playerh = 112;
	dx = 0;//5;
	dy = 0;//5;
	images.addImage("shiphighelf64x112-1.png");
}

public int getx()
{
	return playerx;
}

public int gety()
{
	return playery;
}

public Image getImage()
{
	return images.getImage();
}

public void movePWithKey(int key)
{

           if (key == KeyEvent.VK_LEFT)
            {
		if (dx!=0)	dx = 0;
		else dx = -5;
            }
            else if (key == KeyEvent.VK_RIGHT)
            {
		if (dx!=0) dx = 0;
		else dx = 5;
            }
            if (key == KeyEvent.VK_UP)
            {
		if (dy!=0) dy = 0; 
		else dy = -5;
            }
            else if (key == KeyEvent.VK_DOWN)
            {
		if (dy!=0) dy = 0;
		else dy = 5;
            }
}

public void move() 
{
	playerx += dx;
	playery += dy;
	if (playerx < dx)
		playerx = dx; 
	if (playerx > 800-dx-playerw)
		playerx = 800-dx-playerw; 
	if (playery < dy)
		playery = dy; 
	if (playery > 600-dy-playerh)
		playery = 600-dy-playerh; 
}



public void shootP(int key, LinkedList<Bullet> l)
{
            if (key == KeyEvent.VK_F)
            {
		Bullet bullet = new Bullet(getx()+12,gety(),"bullet24x24-1.png");
		bullet.setdy(-6);
		l.add(bullet);
            }
}

public double distance(int x1, int x2, int y1, int y2)
{
	return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
public boolean collision(Entity e)
{
	if (distance(e.getx(), playerx, e.gety(), playery) < 30) {
		System.out.println("collision with player...gameover.");
		System.exit(99);	
		return true;
	}
	else
		return false;
}
public int movePWithKeyLevel3(int k)
{
	//subclass resp
	return 0;
}
public int movePWithKeyLevel2(int k)
{
	//subclass resp
	return 0;
}

public void setFriendlyBullets(LinkedList<Bullet> l)
{
	friendlybullets = l;
}

public void moveP()
{
  	movePWithKey(key);
  	shootP(key, friendlybullets);
}

public void setKey(int k)
{
	key = k;
}
};
